/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: HP
 * Date: 2023 -04 -04
 * Time: 22:09
 */
class Lotion {
    private int row;
    private int col;
    private int maxPrimeValue;
    private int[][] element;

    public Lotion(int[][] element) {
        this.row = element.length;
        this.col = element[0].length;
        this.element = new int[row][col];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                this.element[i][j] = element[i][j];
            }
        }
        maxPrimeValue = -1;
    }

    private boolean check(int num) {
        if (num < 2) return false;
        for (int i = 2; i <= Math.sqrt(num); i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }

    private void funcFind() {
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                if (check(element[i][j])) {
                    maxPrimeValue = Math.max(maxPrimeValue, element[i][j]);
                }
            }
        }
    }

    public int getMaxPrimeValue() {
        if (maxPrimeValue == -1) {
            funcFind();
        }
        return maxPrimeValue;
    }

    public static void main(String[] args) {
        int[][] e1 = {{1, 3, 5, 7, 9}};
        int[][] e2 = {{1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}};
        int[][] e3 = {{1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}, {11, 22, 33, 44, 55}};
        int[][] e4 = {{1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}, {11, 22, 33, 44, 55}, {13, 37, 14, 29, 61}};
        System.out.println(new Lotion(e1).getMaxPrimeValue());
        System.out.println(new Lotion(e2).getMaxPrimeValue());
        System.out.println(new Lotion(e3).getMaxPrimeValue());
        System.out.println(new Lotion(e4).getMaxPrimeValue());
    }
}

